from python_baway.review.review_2021_02_18Thu.birthdays.xperson_names import xmale_names, xfemale_names
from python_baway.review.review_2021_02_18Thu.birthdays.xrandom_birthdays import xget_a_random_birthday
import random
import datetime
import string
from python_baway.app.xcn_id_suffix import get_cn_id_suffix


def xget_persons_names_and_birthdays(xmale_cnt, xfemale_cnt,
                                     xbottom_dt=datetime.datetime(1970, 1, 1, 0, 0, 0),
                                     xtop_dt=datetime.datetime.now()):
    xresult = []

    def xdo_it(cnt, xnames, xgender):
        for i in range(cnt):
            xname = random.choice(xnames)
            xbirthday = xget_a_random_birthday(xbottom_dt, xtop_dt)
            xid01 = ''.join(random.choices(string.digits, k=6))
            xid02 = xbirthday.strftime('%Y%m%d')
            if 'm' == xgender:
                xid03 = random.randrange(1, 999, 2)
            else:
                xid03 = random.randrange(2, 999, 2)
            xid03 = f'{xid03:03d}'
            xid_prefix = xid01 + xid02 + xid03
            xid_suffix = get_cn_id_suffix(xid_prefix)
            xid = xid_prefix + xid_suffix
            xresult.append((xname, xbirthday, xgender, xid))

    xdo_it(xmale_cnt, xmale_names, 'm')
    xdo_it(xfemale_cnt, xfemale_names, 'f')
    random.shuffle(xresult)
    return xresult
